home *** CD-ROM | disk | FTP | other *** search
- /* Copyright © 1995-1996 : David Atkinson */
- /* V1.21 Menus.c */
- /* Calgor */
-
- #include <hold/extra.h>
- #include <hold/funchead.h>
-
- #include <intuition/intuition.h>
-
- #include <graphics/gfx.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/copper.h>
- #include <graphics/view.h>
- #include <graphics/text.h>
- #include <graphics/sprite.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <string.h>
- #include <signal.h>
-
- #include <exec/libraries.h>
-
- #include <graphics/gfxnodes.h>
- #include <graphics/displayinfo.h>
- #include <graphics/videocontrol.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/diskfont_protos.h>
- #include <utility/tagitem.h>
-
- #ifdef(V3)
- #include <graphics/modeid.h>
- #endif
-
- extern void get_source(char *);
- extern void handler(int);
- extern void showcode(void);
- extern void play_col(int);
- extern void ff_col(int);
- extern void clr_code(void);
- extern void killsprite(void);
- extern void clean_local(void);
- extern void al_clean(void);
- extern void clr_dem(void);
- extern void select(void);
- extern void set_sprite(void);
- extern void reset_sprites(void);
- extern void chk_view(struct View *, struct View *);
- extern SHORT anim_button(void);
- extern SHORT menu_button(void);
- extern void open_log(void);
- extern void close_file(void);
- extern void write_file(char *);
- extern void back_drop(void);
- extern void shutdown(void);
- extern void clearkeybuf(void);
- extern void draw_modes(UBYTE,struct RastPort *,long,long,UBYTE);
-
- extern struct Window *my_window;
- extern struct Screen *my_screen;
- extern SHORT squeek[2];
- extern char *buffer, *display;
- extern int last;
- extern int dem_num;
- extern SHORT fraction;
- extern SHORT trip;
- extern struct GfxBase *ps;
- extern BOOL lmbpress;
- extern BOOL wactive;
- extern struct MsgPort *aport;
-
- void cleanup(void);
- void alert(char *);
- void op_liblob(void);
- void viewstart(void);
- void viewportstart(void);
- void bit_init(void);
- void ras_init(void);
- void show_display(int);
- void menu_opt(void);
- void put_back(int);
- void close_display(void);
- void acquire_bits(int);
- void get_palette(int);
- void get_editor(void);
- void copy_object(int, long, long, struct BitMap * );
- void opttext(void);
- void write_opt(int,long);
- void anim_opt(void);
-
- struct Library *IntuitionBase = NULL;
- struct Library *DiskfontBase = NULL;
- struct Library *ConsoleDevice = NULL;
- struct Library *WorkbenchBase = NULL;
- struct GfxBase *GfxBase = NULL;
- struct BitMap ft_bitmap = { NULL };
- struct BitMap sec_bitmap= { NULL };
- struct BitMap thd_bitmap= { NULL };
- struct ViewPort ft_viewport = { NULL };
- struct ViewPort sec_viewport= { NULL };
- struct View ft_view = { NULL };
- struct View sec_view = { NULL };
- struct RastPort ft_rastport = { NULL };
- struct RastPort sec_rastport = { NULL };
- struct RastPort thd_rastport = { NULL };
- struct View *old_view = NULL;
- struct RasInfo ft_rasinfo = { NULL };
- struct RasInfo sec_rasinfo = { NULL };
- struct RasInfo thd_rasinfo = { NULL };
- struct GfxBase *wb = NULL;
- /* For 2.0+ Wb */
- struct ViewExtra *ft_vextra=NULL;
- struct ViewExtra *sec_vextra=NULL;
- struct MonitorSpec *monspec=NULL;
- struct ViewPortExtra *vpone_extra=NULL;
- struct ViewPortExtra *vptwo_extra=NULL;
- struct DimensionInfo dimquery = { NULL };
- struct MonitorInfo monstuff = { NULL };
- struct DisplayInfo distuff = { NULL };
- UWORD vpone_col[COLOURS],vptwo_col[COLOURS];
- ULONG modeID = 0;
-
- UWORD colour_table[VYOUS][COLOURS]; /* Colour Palette */
- char choices[NUMOFOPT][SLENGTH]; /* Options */
- char editor[MAXCHARPATH]; /* Editor Buffer */
- UWORD wb_version = 37; /* WorkBench version, fixed at 37 for now */
- int old_dem=0; /* Dem_num changes a bit, old_dem doesn't */
- UBYTE *keybufptr = NULL; /* Keyboard buffer */
- struct ColorMap *cm = NULL; /* Color map pointer for view one */
- struct ColorMap *cmtwo = NULL; /* Colour map pointer for view two */
- struct IOStdReq ioreq = { NULL };
- struct TagItem voneTags[4] =
- {
- { VTAG_ATTACH_CM_SET, NULL },
- { VTAG_VIEWPORTEXTRA_SET, NULL },
- { VTAG_NORMAL_DISP_SET, NULL },
- { VTAG_END_CM, NULL }
- };
-
- struct TagItem vtwoTags[4] =
- {
- { VTAG_ATTACH_CM_SET, NULL },
- { VTAG_VIEWPORTEXTRA_SET, NULL },
- { VTAG_NORMAL_DISP_SET, NULL },
- { VTAG_END_CM, NULL }
- };
-
- struct TextFont *font_ptr = NULL;
- struct TextFont *cfontptr = NULL;
-
- struct TextAttr opt_font =
- {
- "helvetica.font",
- 13,
- FS_NORMAL,
- FPF_DISKFONT | FPF_DESIGNED
- };
-
- struct TextAttr code_font =
- {
- "topaz.font",
- 8,
- FS_NORMAL,
- FPF_ROMFONT
- };
-
- /* void op_liblob(void)
- Opens up the amigas librarys, shuts down cpu datacaches, sets up modeid, opens
- console Device, sets up input handler, opens fonts and gets memory for keyboard buffer.
- The OpenLibray routines not needed in Dice but needed in SAS/C */
-
- void op_liblob()
- {
- SHORT result=0;
-
- /* Fix for 68030, when on low amount of memory (chip), get problem writing text
- to sreen. See corresponding cpu command in cleanup */
-
- result=system("cpu nodatacache > NIL:");
- IntuitionBase = OpenLibrary("intuition.library",0);
- if (IntuitionBase == 0)
- alert("Failed to open intuition library (op_liblob)\n");
- WorkbenchBase = OpenLibrary("workbench.library",37);
- if(WorkbenchBase == 0)
- alert("Failed to open workbench library 37+ (op_liblob)\n");
- GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 0 );
- if (GfxBase==0)
- alert("Failed to open graphics library (op_liblob)\n");
- wb_version = GfxBase->LibNode.lib_Version;
- if(wb_version < 37)
- alert("Sorry Need WorkBench 37+ To Run\n");
- wb_version=37; /* Fix it for now */
- DiskfontBase = OpenLibrary("diskfont.library", 0 );
- if (DiskfontBase==0)
- alert("Failed to open diskfont library (op_liblob)\n");
-
- wb = (struct GfxBase *) GfxBase;
- if( wb_version<39 ){
- modeID = PAL_MONITOR_ID | HIRESLACE_KEY;
- }
- else{
- modeID = PAL_MONITOR_ID | HIRESLACE_KEY;
- #ifdef(V3)
- modeID = DBLPAL_MONITOR_ID | DBLPALHIRESFF_KEY;
- #endif
- }
- old_view = wb->ActiView;
- /* Open Console Device */
- if (0==OpenDevice("console.device",-1,(struct IORequest *) &ioreq, 0) ){
- ConsoleDevice = (struct Library *) ioreq.io_Device;
- }
- else{
- alert("Failed to open console device (op_liblob)\n");
- }
- signal(SIGINT,handler);
- keybufptr=(UBYTE *) malloc(KEYBUFF);
- if(keybufptr==NULL){
- alert("Failed to allocate memory for keyboard buffer (op_liblob)\n");
- }
- if( !(aport = CreateMsgPort()) ){
- alert("Failed to open message port\n");
- }
- font_ptr=OpenDiskFont(&opt_font);
- if(font_ptr==NULL){
- opt_font.ta_Name = "times.font";
- opt_font.ta_YSize = 11;
- font_ptr=OpenDiskFont(&opt_font);
- }
- if(font_ptr==NULL){
- opt_font.ta_Name = "courier.font";
- opt_font.ta_YSize = 11;
- font_ptr=OpenDiskFont(&opt_font);
- }
- if(font_ptr==NULL){ /* PaniC - Find A font */
- opt_font.ta_Name = "napsa.font";
- opt_font.ta_YSize = 11;
- font_ptr=OpenDiskFont(&opt_font);
- }
- if(font_ptr==NULL){
- alert("Couldn't Open Font: Need helvetica 13 or times 11 or courier 11 or napsa 11\n");
- }
- cfontptr = OpenFont(&code_font);
- if(cfontptr==NULL){
- alert("Couldn't Open topaz.font (8) (op_liblob)\n");
- }
- }
-
- /* void get_palette(int)
- get_palette, reads in palette colours (long words) from
- specified file path number. Have to cast from int to UWORD
- for the palette arrays */
-
- void get_palette(int palnum)
- {
- char *palete_file;
- FILE *fp=NULL;
- int i,col_tab[COLOURS];
-
- switch(palnum){
- case(1):
- palete_file=MENUPALETE;
- break;
- case(2):
- palete_file=DEMPALETE;
- break;
- default:
- clean_local();
- alert("Incorrect Menu label (get_pallete)\n");
- break;
- }
-
- fp = fopen(palete_file,"r");
- if ( fp ){
- for(i=0;i<COLOURS;i++){
- fscanf(fp,"%x",&col_tab[i]);
- /*We have to cast */
- colour_table[palnum-1][i] = (UWORD) col_tab[i];
- }
- fclose( fp );
- }
- else {
- clean_local();
- alert("Couldn't open palette (get_pallete)\n");
- }
- }
-
- void get_editor(void){
- FILE *edfp=NULL;
-
- edfp = fopen(EDITPATH,"r");
- if(edfp){
- fscanf(edfp,"%s",editor);
- fclose(edfp);
- }
- else{
- printf("Failed open data/editor.dat: Defaulting to sys:utilities/multiview \n");
- strcpy(editor,ONETWO);
- }
- }
-
- /* void viewstart(void)
- viewstart initialises the view structure and modes
- LACE, HIRES, 640*512. Note the view structue Dxoffsets
- and DyOffsets are initialised not necasarily set to 0,
- presently set to 129*44. (V1.3) */
-
- void viewstart()
- {
- /* 1.3 Wb */
- InitView(&ft_view);
- if(wb_version>=36){
- ft_view.DxOffset = 0; /* For 2.0+ have to get XY values from monitor database */
- ft_view.DyOffset = 0;
- }
- ft_view.Modes = LACE|HIRES|SPRITES;
- ft_view.ViewPort = &ft_viewport;
- InitView(&sec_view);
- sec_view.ViewPort =&sec_viewport;
- sec_view.Modes = LACE|HIRES|SPRITES;
- if(wb_version>=36){
- sec_view.DxOffset = 0;
- sec_view.DyOffset = 0;
- }
- /* 2.0+ Wb */
- if(wb_version>=36){
- ft_vextra=GfxNew(VIEW_EXTRA_TYPE);
- sec_vextra=GfxNew(VIEW_EXTRA_TYPE);
- if( ! ((ft_vextra == NULL) || (sec_vextra==NULL)) ){
- GfxAssociate(&ft_view, ft_vextra);
- ft_view.Modes = LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
- GfxAssociate(&sec_view, sec_vextra);
- sec_view.Modes = LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
- if(monspec=OpenMonitor(NULL,modeID) ){
- ft_vextra->Monitor=monspec;
- sec_vextra->Monitor=monspec;
- }
- else{
- clean_local();
- alert("Could not get Monitor Spec (viewstart)\n");
- }
- }
- else{
- clean_local();
- alert("Could not allocate viewextra (viewstart)\n");
- }
- }
- }
-
- /* void viewportstart(void)
- Initiliases the viewport structure. DX and DY Offsets are
- set to 0 (by InitVPort) (wb1.3). I have selected hires and interlace
- modes. Remember to initialise the colour table before issuing
- this function. */
-
- void viewportstart()
- {
- UWORD *colorptr=NULL;
-
- int loop;
- ULONG size;
-
- for(loop=0;loop<COLOURS;loop++){
- vpone_col[loop]=colour_table[0][loop];
- vptwo_col[loop]=colour_table[1][loop];
- }
- InitVPort(&ft_viewport);
- ft_viewport.Next = NULL;
- ft_viewport.DWidth = WIDTH;
- ft_viewport.DHeight = HEIGHT;
- ft_viewport.Modes = LACE|HIRES|SPRITES;
- ft_viewport.RasInfo = &ft_rasinfo;
- /* 2.0+ */
- cm = (struct ColorMap *) GetColorMap( COLOURS * 2 );
- if(cm==NULL){
- clean_local();
- alert("Couldn't allocate first colour map (viewportstart)\n");
- }
- if(wb_version>=36){
- ft_viewport.Modes=LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
- vpone_extra=GfxNew(VIEWPORT_EXTRA_TYPE);
- if(vpone_extra!=NULL){
- voneTags[1].ti_Data = (ULONG) vpone_extra;
- size = (ULONG) sizeof(monstuff);
- /* Get Monitor Details */
- if(GetDisplayInfoData(NULL,(UBYTE *) &monstuff,size,DTAG_MNTR,modeID) == 0){
- clean_local();
- alert("Couldn't access display database - MonitorInfo (viewportstart)\n");
- }
- size = (ULONG) sizeof(distuff);
- /* Get Display Details */
- if(GetDisplayInfoData(NULL,(UBYTE *) &distuff,size,DTAG_DISP,modeID) == 0){
- clean_local();
- alert("Couldn't access display database - MonitorInfo (viewportstart)\n");
- }
- /* Putting correct monitor positions */
- ft_view.DxOffset = sec_view.DxOffset = monstuff.ViewPosition.x;
- ft_view.DyOffset = sec_view.DyOffset = monstuff.ViewPosition.y;
- size = (ULONG) sizeof(dimquery);
- /* Get dimension details */
- if(GetDisplayInfoData(NULL,(UBYTE *) &dimquery,size,DTAG_DIMS,modeID) != 0){
- vpone_extra->DisplayClip = dimquery.Nominal;
- voneTags[2].ti_Data = (ULONG) FindDisplayInfo(modeID);
- if(voneTags[2].ti_Data == NULL){
- clean_local();
- alert("Could not get the DimensionInfo (viewportstart)\n");
- }
- }
- else{
- clean_local();
- alert("Could not get DimensionInfo (viewportstart)\n");
- }
- }
- else{
- clean_local();
- alert("Couldn't allocate viewport1 extra (viewportstart)\n");
- }
- voneTags[0].ti_Data = (ULONG) &ft_viewport;
- if( VideoControl(cm,voneTags)!=NULL ){
- clean_local();
- alert("Could not attach ft_viewport (viewportstart)\n");
- }
- LoadRGB4(&ft_viewport,vpone_col,16);
- }
- else{
- ft_viewport.ColorMap = cm;
- }
- InitVPort(&sec_viewport);
- sec_viewport.Next = NULL;
- sec_viewport.DWidth = WIDTH;
- sec_viewport.DHeight = HEIGHT;
- sec_viewport.Modes = HIRES|LACE|SPRITES;
- sec_viewport.RasInfo = &sec_rasinfo;
- cmtwo = (struct ColorMap *) GetColorMap( COLOURS * 2 ); /* Was X2 */
- if(cmtwo==NULL){
- clean_local();
- alert("Couldn't alloacte second color map (viewportstart)\n");
- }
- if(wb_version>=36){
- sec_viewport.Modes=LACE|HIRES|SPRITES|EXTEND_VSTRUCT;
- if(vptwo_extra = GfxNew(VIEWPORT_EXTRA_TYPE) ) {
- vtwoTags[1].ti_Data = (ULONG) vptwo_extra;
- vptwo_extra->DisplayClip = dimquery.Nominal;
- if( !(vtwoTags[2].ti_Data = (ULONG) FindDisplayInfo(modeID) ) ){
- clean_local();
- alert("Could not get the DisplayInfo (viewportstart)\n");
- }
- }
- else{
- clean_local();
- alert("Couldn't allocate viewport extra (viewportstart)\n");
- }
- vtwoTags[0].ti_Data = (ULONG) &sec_viewport;
- if( VideoControl(cmtwo,vtwoTags) ){
- clean_local();
- alert("Could not attach sec_viewport (viewportstart)\n");
- }
- LoadRGB4(&sec_viewport,vptwo_col,16);
- }
- else{
- sec_viewport.ColorMap = cmtwo;
- colorptr =(UWORD *) ft_viewport.ColorMap->ColorTable;
- for (loop=0;loop<COLOURS;loop++){
- *colorptr++ = colour_table[0][loop];
- }
- colorptr =(UWORD *) sec_viewport.ColorMap->ColorTable;
- for (loop=0;loop<COLOURS;loop++){
- *colorptr++ = colour_table[1][loop];
- }
- }
- }
-
- void bit_init()
- {
- int loop;
-
- /* The WaitBlits are a stab at trying to fix the text corruption problem */
-
- InitBitMap( &ft_bitmap, DEPTH, WIDTH, HEIGHT );
- for( loop = 0; loop < DEPTH; loop++ )
- {
- ft_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
- if( ft_bitmap.Planes[ loop ] == NULL )
- alert("Failed Bitmap allocation 1 (bit_init)\n");
- WaitBlit();
- BltClear( ft_bitmap.Planes[ loop ],
- RASSIZE( WIDTH, HEIGHT ), 0 );
- }
- WaitBlit();
- InitBitMap( &sec_bitmap, DEPTH, WIDTH, HEIGHT );
- for( loop = 0; loop < DEPTH; loop++ )
- {
- sec_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
- if( sec_bitmap.Planes[ loop ] == NULL )
- alert("Failed Bitmap allocation 2 (bit_init)\n");
- WaitBlit();
- BltClear( sec_bitmap.Planes[ loop ],
- RASSIZE( WIDTH, HEIGHT ), 0 );
- }
- WaitBlit();
- InitBitMap( &thd_bitmap, DEPTH, WIDTH, HEIGHT );
- for( loop = 0; loop < DEPTH; loop++ )
- {
- thd_bitmap.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
- if( thd_bitmap.Planes[ loop ] == NULL )
- alert("Failed Bitmap allocation 3 (bit_init)\n");
- WaitBlit();
- BltClear( thd_bitmap.Planes[ loop ],
- RASSIZE( WIDTH, HEIGHT ), 0 );
- }
- WaitBlit();
- }
-
- void ras_init()
- {
- ft_rasinfo.BitMap = &ft_bitmap;
- ft_rasinfo.RxOffset = RX_OFFSET;
- ft_rasinfo.RyOffset = RY_OFFSET;
- ft_rasinfo.Next = NULL;
- InitRastPort(&ft_rastport);
-
- ft_rastport.BitMap=&ft_bitmap;
- ft_rastport.Mask = 0xFF;
-
- sec_rasinfo.BitMap = &sec_bitmap;
- sec_rasinfo.RxOffset = RX_OFFSET;
- sec_rasinfo.RyOffset = RY_OFFSET;
- sec_rasinfo.Next = NULL;
- InitRastPort(&sec_rastport);
- sec_rastport.BitMap=&sec_bitmap;
- sec_rastport.Mask = 0xFF;
-
- thd_rasinfo.BitMap = &thd_bitmap;
- thd_rasinfo.RxOffset = RX_OFFSET;
- thd_rasinfo.RyOffset = RY_OFFSET;
- thd_rasinfo.Next = NULL;
- InitRastPort(&thd_rastport);
- thd_rastport.BitMap=&thd_bitmap;
- }
-
- void show_display(int vselect)
- {
- switch(vselect){
- case(1):
- MakeVPort(&ft_view, &ft_viewport );
- MrgCop(&ft_view);
- LoadView(&ft_view);
- break;
- case(2):
- MakeVPort(&sec_view, &sec_viewport );
- MrgCop(&sec_view);
- LoadView(&sec_view);
- set_sprite();
- reset_sprites();
- break;
- default:
- clean_local();
- alert("Failed view selection (prep_hardware)\n");
- break;
- }
- }
-
- /* The status when we hit this routine is that the second view and viewport
- are showing */
-
- void anim_opt(void)
- {
- char filename[MAXCHARPATH];
- SHORT butpress=0;
- ULONG check;
-
- old_dem=dem_num;
- show_display(2);
- while(dem_num!=-1){
-
- check = LockIBase(0);
- ps = (struct GfxBase *) GfxBase;
- UnlockIBase(check);
- chk_view(ps->ActiView,&sec_view);
- raise(SIGINT);
- butpress = anim_button();
- clearkeybuf();
- #ifdef(TEST)
- squeek[1] = 27;
- squeek[0] = 19;
- wactive=lmbpress=TRUE;
- dem_num=old_dem = 4;
- butpress = PLAYBUT;
- #endif
-
- switch(butpress){
- case PLAYBUT : case NUM1KEY :
- /* PLAY BUTTON */
- dem_num=old_dem;
- strcpy(filename,ONEONE);
- strcat(filename,&choices[8+(old_dem*2)][0]);
- strcat(filename,".c");
- clr_code();
- clr_dem();
- reset_sprites();
- play_col(1);
- get_source(filename);
- showcode();
- switch (dem_num){
- case 100:
- break;
- case 1:
- ifelse_control();
- break;
- case 2 :
- switch_control();
- break;
- case 3 :
- for_control();
- break;
- case 4 :
- while_control();
- break;
- case 5 :
- dowhile_control();
- break;
- case 6:
- array_control();
- break;
- case 11 :
- bubble_control();
- break;
- case 12 :
- insert_control();
- break;
- case 13 :
- select_control();
- break;
- case 14 :
- quick_control();
- break;
- case 21:
- user1_control();
- break;
- case 22:
- user2_control();
- break;
- case 23:
- user3_control();
- break;
- case 24:
- user4_control();
- break;
- case 25:
- user5_control();
- break;
- default :
- clean_local();
- printf("Falied to lock %d\n",dem_num);
- alert("Failed to get opt num (anim_opt)\n");
- break;
- }
- play_col(0);
- ff_col(0);
- #ifdef TEST
- clean_local();
- alert("Finished test\n");
- #endif
- break;
- case EJECTBUT : case ESCKEY :
- /* EJECT BUTTON */
- clean_local();
- clr_code();
- clr_dem();
- dem_num=-1;
- show_display(1);
- break;
- case INFOBUT : case NUM5KEY :
- /* INFORMATION BUTTON */
- killsprite();
- shutdown();
- LoadView(old_view);
- strcpy(filename,editor);
- strcat(filename," ");
- strcat(filename,ONETHREE);
- strcat(filename,&choices[8+(old_dem*2)][0]);
- strcat(filename,".txt");
- system(filename);
- back_drop();
- LoadView(&sec_view);
- set_sprite();
- reset_sprites();
- break;
- default :
- break;
- }
- }
- }
-
- void menu_opt(void)
- {
- ULONG chit;
- SHORT key=0;
-
- while(dem_num==-1){
- chit = LockIBase(0);
- ps = (struct GfxBase *) GfxBase;
- UnlockIBase(chit);
- chk_view(ps->ActiView,&ft_view);
- raise(SIGINT);
- key=menu_button();
- clearkeybuf();
- /* F1 Option 1 */
- if ( (key==F1BUTTON) && (last!=0) ){
- copy_object(1,55,93,&ft_bitmap);
- put_back(last);
- last=0;
- write_opt(0,MBLACK);
- }
- /* F2 Option 2 */
- if ( (key==F2BUTTON) && (last!=1) ){
- copy_object(1,169,93,&ft_bitmap);
- put_back(last);
- last=1;
- write_opt(1,MBLACK);
- }
-
- /* F3 Option 3 */
- if ( (key==F3BUTTON) && (last!=2) ){
- copy_object(1,283,93,&ft_bitmap);
- put_back(last);
- last=2;
- write_opt(2,MBLACK);
- }
-
- /* F4 Option 4 */
- if ( (key==F4BUTTON) && (last!=3) ){
- copy_object(1,397,93,&ft_bitmap);
- put_back(last);
- last=3;
- write_opt(3,MBLACK);
- }
-
- /* F5 Option 5 */
- if ( (key==F5BUTTON) && (last!=4) ){
- copy_object(1,511,93,&ft_bitmap);
- put_back(last);
- last=4;
- write_opt(4,MBLACK);
- }
-
- /* Scan y coords for key options */
- #ifdef(TEST)
- last=0;
- key = NUM4KEY;
- #endif
- switch(key){
- case NUM1KEY:
- dem_num=(last*5+1);
- if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
- anim_opt();
- else
- dem_num=-1;
- break;
- case NUM2KEY:
- dem_num=(last*5+2);
- if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
- anim_opt();
- else
- dem_num=-1;
- break;
- case NUM3KEY:
- dem_num=(last*5+3);
- if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
- anim_opt();
- else
- dem_num=-1;
- break;
- case NUM4KEY:
- dem_num=(last*5+4);
- if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
- anim_opt();
- else
- dem_num=-1;
- break;
- case NUM5KEY:
- dem_num=(last*5+5);
- if( (choices[8+(dem_num*2)][0]!='\0') && (choices[8+(dem_num*2)][0]!='!') )
- anim_opt();
- else
- dem_num=-1;
- break;
- case ESCKEY :
- LoadView(old_view);
- cleanup();
- exit(0);
- break;
- default:
- dem_num=-1;
- break;
- }
- }
- }
-
- void put_back(int where)
- {
- switch(where){
- case(0):
- copy_object(2,55,93,&ft_bitmap);
- write_opt(0,MWHITE);
- break;
- case(1):
- copy_object(2,169,93,&ft_bitmap);
- write_opt(1,MWHITE);
- break;
- case(2):
- copy_object(2,283,93,&ft_bitmap);
- write_opt(2,MWHITE);
- break;
- case(3):
- copy_object(2,397,93,&ft_bitmap);
- write_opt(3,MWHITE);
- break;
- case(4):
- copy_object(2,511,93,&ft_bitmap);
- write_opt(4,MWHITE);
- break;
- default:
- clean_local();
- alert("Failed (put_back)\n");
- break;
- }
- }
-
- void cleanup()
- {
- int loop;
-
- if(font_ptr) CloseFont(font_ptr);
- if(cfontptr) CloseFont(cfontptr);
- system("cpu datacache > NIL:");
- al_clean();
- if(keybufptr!=NULL) free(keybufptr);
- FreeCprList( ft_view.LOFCprList );
- FreeCprList( sec_view.LOFCprList );
- FreeCprList( ft_view.SHFCprList );
- FreeCprList( sec_view.SHFCprList );
- FreeVPortCopLists( &ft_viewport );
- FreeVPortCopLists( &sec_viewport);
-
- /*Because both screens are interlaced they have two seperate
- copperlists, stored in the "view.SHFCprList" */
-
- for( loop = 0; loop < DEPTH; loop++ ){
- if( ft_bitmap.Planes[ loop ] )
- FreeRaster( ft_bitmap.Planes[ loop ], WIDTH, HEIGHT );
- }
- for( loop = 0; loop < DEPTH; loop++ ){
- if( sec_bitmap.Planes[ loop ] )
- FreeRaster( sec_bitmap.Planes[ loop ], WIDTH, HEIGHT );
- }
- for( loop = 0; loop < DEPTH; loop++ ){
- if( thd_bitmap.Planes[ loop ] )
- FreeRaster( thd_bitmap.Planes[ loop ], WIDTH, HEIGHT );
- }
- if(wb_version>=37){
- if( ft_vextra ) GfxFree(ft_vextra);
- if( sec_vextra ) GfxFree(sec_vextra);
- if( vpone_extra) GfxFree(vpone_extra);
- if( vptwo_extra) GfxFree(vptwo_extra);
- if( monspec ) CloseMonitor( monspec );
- }
- if( ft_viewport.ColorMap != NULL ) FreeColorMap( ft_viewport.ColorMap );
- if( sec_viewport.ColorMap != NULL ) FreeColorMap( sec_viewport.ColorMap );
- shutdown(); /* Close Window and screen safely */
- if( buffer != NULL ){
- free(buffer);
- buffer=NULL;
- }
- if( display != NULL){
- free(display);
- display=NULL;
- }
- if( aport ) {
- DeleteMsgPort(aport);
- aport=NULL;
- }
- if( ConsoleDevice != NULL) CloseDevice( (struct IORequest *) &ioreq);
- if( DiskfontBase != NULL) CloseLibrary(DiskfontBase);
- if( GfxBase != NULL) CloseLibrary( (struct Library *) GfxBase );
- if( WorkbenchBase ) CloseLibrary(WorkbenchBase);
- if( IntuitionBase != NULL ) CloseLibrary( IntuitionBase );
- }
-
- /* void aquire_bits(int)
-
- Take the picture number as an argument and loads in
- the bitmap accordingly */
-
- void acquire_bits(int picnum)
- {
-
- int aplane,aline,fh,segment;
- char buffer[WIDTH/8*16], *pic_file;
- UBYTE *bitptr=NULL;
- struct BitMap the_bitmap;
-
- switch(picnum){
- case(1):
- pic_file=MENUPATH;
- the_bitmap = ft_bitmap;
- break;
- case(2):
- pic_file=DEMPATH;
- the_bitmap = sec_bitmap;
- break;
- case(3):
- pic_file=DUMPPATH;
- the_bitmap = thd_bitmap;
- break;
- default:
- clean_local();
- alert("Incorrect picture number label");
- break;
- }
-
- fh = open(pic_file,O_RDONLY);
- if (fh<0){
- clean_local();
- alert("Couldn't open data file\n");
- }
- for(aplane=0;aplane<DEPTH;aplane++){
- bitptr = (UBYTE *) (the_bitmap.Planes[aplane] );
- for(segment=0;segment<HEIGHT/16;segment++){
- read(fh,buffer,WIDTH*2);
- for(aline=0;aline<WIDTH*2;aline++){
- *bitptr++ = (UBYTE) buffer[aline];
- }
- }
- }
- close(fh);
- }
-
- void copy_object(int object, long dx, long dy, struct BitMap *dest_bm)
- {
-
- struct BitMap *source_bm;
- long sx, sy, mw, mh, flag, mask;
-
- flag = 0xC0; /* Normal copy */
- mask = 0xFF; /* Use all bitplanes */
-
- switch(object){
- case 1 :
- /* OPTION ON */
- sx = 1L;
- sy = 1L;
- source_bm= &thd_bitmap;
- mw = 79;
- mh = 53;
- break;
- case 2 :
- /* OPTION OFF */
- sx = 82L;
- sy = 1L;
- source_bm=&thd_bitmap;
- mw = 79;
- mh = 53;
- break;
- case 3 :
- /* VARIABLE */
- sx = 178L;
- sy = 2L;
- source_bm=&thd_bitmap;
- mw = 46;
- mh = 58;
- break;
- case 4 :
- /* HOLE */
- sx = 240L;
- sy = 2L;
- source_bm=&thd_bitmap;
- mw = 53;
- mh = 53;
- break;
- case 5 :
- /* VBB */
- sx = 298L;
- sy = 2L;
- source_bm=&thd_bitmap;
- mw = 6;
- mh = 18;
- break;
- case 6 :
- /* HBB */
- sx = 298L;
- sy = 24L;
- source_bm=&thd_bitmap;
- mw = 18;
- mh = 6;
- break;
- case 7 :
- /* FILL */
- sx = 307L;
- sy = 2L;
- source_bm=&thd_bitmap;
- mw = 8;
- mh = 6;
- break;
- case 8 :
- /* IAR */
- sx = 319L;
- sy = 2L;
- source_bm=&thd_bitmap;
- mw = 46;
- mh = 22;
- break;
- case 9 :
- /* IOFF */
- sx = 319L;
- sy = 29L;
- source_bm=&thd_bitmap;
- mw = 16;
- mh = 15;
- break;
- case 10 :
- /* ION */
- sx = 338L;
- sy = 29L;
- source_bm=&thd_bitmap;
- mw = 16;
- mh = 15;
- break;
- default:
- clean_local();
- alert("Object doesn't exist (copy_object)\n");
- break;
- }
- WaitBlit(); /* Make sure we have blitter */
- BltBitMap(source_bm, sx, sy, dest_bm, dx, dy, mw, mh, flag, mask, NULL);
- }
-
- void opttext()
- {
- int line, letter;
- char c;
- FILE *file;
-
- for(line=0;line<NUMOFOPT;line++){
- for(letter=0;letter<SLENGTH;letter++){
- choices[line][letter]='\0';
- }
- }
- line=letter=c=0;
- file=fopen(OPTTPATH,"r");
- if(file!=NULL){
- while( (c!=EOF) && (letter<SLENGTH) && (line<NUMOFOPT) ){
- c= fgetc(file);
- switch(c){
- case '\n' :
- choices[line][letter]= '\0';
- line++;
- letter=0;
- break;
- case EOF :
- break;
- default :
- choices[line][letter]= c;
- letter++;
- break;
- }
- }
- fclose(file);
- }
- else{
- clean_local();
- alert("Couldn't open options file (opttext)\n");
- }
- }
-
- void write_opt(int select, long color)
- {
- int index;
-
- index = 10 * select;
- draw_modes(0xFF,&ft_rastport,MBAGE,0L,JAM1);
- SetFont(&ft_rastport,font_ptr);
- /* Write text to option squares */
- if (color!=MWHITE){
- Move(&ft_rastport,67,113);
- Text(&ft_rastport, &choices[0][0], strlen(&choices[0][0]) );
- Move(&ft_rastport,67,126);
- Text(&ft_rastport, &choices[1][0], strlen(&choices[1][0]) );
- Move(&ft_rastport,181,113);
- Text(&ft_rastport, &choices[2][0], strlen(&choices[2][0]) );
- Move(&ft_rastport,181,126);
- Text(&ft_rastport, &choices[3][0], strlen(&choices[3][0]) );
- Move(&ft_rastport,295,113);
- Text(&ft_rastport, &choices[4][0], strlen(&choices[4][0]) );
- Move(&ft_rastport,295,126);
- Text(&ft_rastport, &choices[5][0], strlen(&choices[5][0]) );
- Move(&ft_rastport,409,113);
- Text(&ft_rastport, &choices[6][0], strlen(&choices[6][0]) );
- Move(&ft_rastport,409,126);
- Text(&ft_rastport, &choices[7][0], strlen(&choices[7][0]) );
- Move(&ft_rastport,523,113);
- Text(&ft_rastport, &choices[8][0], strlen(&choices[8][0]) );
- Move(&ft_rastport,523,126);
- Text(&ft_rastport, &choices[9][0], strlen(&choices[9][0]) );
- }
- /*Write text to key sections */
- draw_modes(0xFF,&ft_rastport,color,0L,JAM1);
- Move(&ft_rastport,158,370);
- Text(&ft_rastport,&choices[10+index][0], strlen(&choices[10+index][0]) );
- Move(&ft_rastport,158,387);
- Text(&ft_rastport,&choices[11+index][0], strlen(&choices[11+index][0]) );
- Move(&ft_rastport,331,370);
- Text(&ft_rastport,&choices[12+index][0], strlen(&choices[12+index][0]) );
- Move(&ft_rastport,331,387);
- Text(&ft_rastport,&choices[13+index][0], strlen(&choices[13+index][0]) );
- Move(&ft_rastport,504,370);
- Text(&ft_rastport,&choices[14+index][0], strlen(&choices[14+index][0]) );
- Move(&ft_rastport,504,387);
- Text(&ft_rastport,&choices[15+index][0], strlen(&choices[15+index][0]) );
- Move(&ft_rastport,158,464);
- Text(&ft_rastport,&choices[16+index][0], strlen(&choices[16+index][0]) );
- Move(&ft_rastport,158,481);
- Text(&ft_rastport,&choices[17+index][0], strlen(&choices[17+index][0]) );
- Move(&ft_rastport,331,464);
- Text(&ft_rastport,&choices[18+index][0], strlen(&choices[18+index][0]) );
- Move(&ft_rastport,331,481);
- Text(&ft_rastport,&choices[19+index][0], strlen(&choices[19+index][0]) );
- }
-
- void alert(char *message)
- {
- open_log();
- write_file(message);
- close_file();
- perror(message);
- LoadView(old_view);
- cleanup();
- exit(20);
- }
-
-